package com.hubei.car.controller;

import com.hubei.car.annotation.PostApi;
import com.hubei.car.entity.Result;
import com.hubei.car.service.MsProductService;
import com.hubei.car.swaggerParam.MsInquiryAddParam;
import com.hubei.car.swaggerParam.MsProductQueryParam;
import com.hubei.car.swaggerParam.MsProductTypeQueryParam;
import com.hubei.car.utils.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 产品接口
 * @author huanghaiasheng
 * @create 2019-11-26
 */
@RestController
@Api(value = "产品接口",tags = "产品接口")
@RequestMapping("/msProduct")
public class MsProductController {

    @Autowired
    private MsProductService msProductService;
    @Autowired
    UserUtil userUtil;

    @PostApi(value = "/queryMsProductTypeTree", auth = false)
    @ApiOperation("产品目录查询(树形结构,所有数据)")
    public Result queryMsProductTypeTree(){
        return msProductService.queryMsProductTypeTree();
    }

    @PostApi(value = "/queryMsProductTypePage", auth = false)
    @ApiOperation("产品目录查询")
    public Result queryMsProductTypePage(@RequestBody @Valid MsProductTypeQueryParam msProductTypeQueryParam){
        msProductTypeQueryParam.setIs_index_recommend(true);
        msProductTypeQueryParam.setSize(999L);
        return msProductService.queryMsProductTypePage(msProductTypeQueryParam);
    }

    @PostApi(value = "/queryMsProductPage", auth = false)
    @ApiOperation("产品查询")
    public Result queryMsProductPage(@RequestBody @Valid MsProductQueryParam msProductQueryParam){
        return msProductService.queryMsProductPageXml(msProductQueryParam);
    }

    @PostApi(value = "/setMyFavoriteCar/{id}")
    @ApiOperation("我的爱车")
    public Result setMyFavoriteCar(@PathVariable("id") Long id){
        return msProductService.setMyFavoriteCar(id, userUtil.getCurrentUser());
    }

    @PostApi(value = "/addMsInquiry")
    @ApiOperation("询价")
    public Result addMsInquiry(@RequestBody @Valid MsInquiryAddParam msInquiryAddParam){
        return msProductService.addMsInquiry(msInquiryAddParam, userUtil.getCurrentUser());
    }

    @PostApi(value = "/queryRecommendImages", auth = false)
    @ApiOperation("首页推荐9图")
    public Result queryRecommendImages() {
        return msProductService.queryRecommendImages();
    }

}
